package com.wanshi.servlet;

import com.alibaba.fastjson.JSON;
import com.wanshi.entity.Result;
import com.wanshi.entity.Type;
import com.wanshi.service.TypeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/types")
public class types extends HttpServlet {

    private TypeService typeService = new TypeService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //到数据库查询所有type
        List<Type> list = typeService.list();

        //response.getWri
        response.getWriter().write(JSON.toJSONString(   Result.ok(list)  ) );
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}

